<?php
/**
 * @Name: UsersRoleServices.php
 * @Author: yashuai<1762910894@qq.com>
 */

namespace app\common\services\rbac;

use app\common\services\BaseServices;
use app\common\logic\rbac\UsersRoleLogic;

class UsersRoleServices extends BaseServices
{

    public function __construct(UsersRoleLogic $logic)
    {
        $this->logic = $logic;
    }

    /**
     * @Desc 用户设置角色
     * @param array $params
     * @return bool
     * @author yashuai<1762910894@qq.com>
     */
    public function setUserRole(array $params)
    {
        /** @var RoleServices $roleService */
        $roleService = app()->make(RoleServices::class);
        $role        = $roleService->column([['RoleID', 'in', $params['RoleID']]], 'RoleID');
        if (!empty($role)) {
            $data = [];
            foreach ($role as $roleID) {
                $data[] = [
                    'RoleID' => $roleID,
                    'UserID' => $params['UserID'],
                ];
            }
            /** @var UsersRoleServices $userRoleService */
            $userRoleService = app()->make(UsersRoleServices::class);
            $userRoleService->physicalDeleteRow(['UserID' => $params['UserID']]);
            $userRoleService->createRowAll($data);
        }
        return true;
    }


}
